#pragma once

#include "MsgRouter.h"
#include "1700_account.pb.h"
#include "agency.h"
#include "gameinfo.h"

class ActionLogin
{
public:
    static bool Init();
    
public:
    enum Error
    {
        SUCCESS,
        FAILED,
        INVALID_KEY,
        API_AUTH_FAILED,
        SITE_MASTER_NOT_FOUND,
        SITE_MASTER_NOT_MISMATCH,
        INVALID_CURRENCY_FROM_AUTH,
    };
    static inline std::string ToString(Error err)
    {
        switch (err)
        {
        case SUCCESS: return "success";
        case FAILED: return "failed";
        case INVALID_KEY: return "Invalid Key";
        case API_AUTH_FAILED: return "api auth fail";
        case SITE_MASTER_NOT_FOUND: return "Site master not found";
        case SITE_MASTER_NOT_MISMATCH: return "Site master mismatched";
        case INVALID_CURRENCY_FROM_AUTH: return "invalid currency from auth";
        default: return "error";
        }
    }
    static inline std::int32_t ToCode(Error err)
    {
        switch (err)
        {
        case SUCCESS: return 0;
        case FAILED: return 9;
        case INVALID_KEY: return 2;
        case API_AUTH_FAILED: return 9;
        case SITE_MASTER_NOT_FOUND: return 9;
        case SITE_MASTER_NOT_MISMATCH: return 9;
        case INVALID_CURRENCY_FROM_AUTH: return 104;
        default: return 9;
        }
    }

public:
    static void HandleLogin(HttpData&& data);
    static void ResponseLogin(std::uint32_t request_id, const std::uint64_t request_time, Error err, const std::string& url = "", std::uint32_t display_mode = 0);
    static void OnAgencyGet(stAgency* agency, std::int32_t err_code, std::string&& trans);
    static void OnGameinfoGet(stGameInfo* gameinfo, std::int32_t err_code, std::string&& trans);
    static void OnGenLoginToken(account_proto::GenLoginTokenResp&& get_token_resp);
    static void agencyProc(const std::uint32_t request_id, const std::uint64_t request_time, const std::string& ip, std::string& token, const std::uint32_t gameid, const std::string& lang
        , std::string& agency, const std::string& key, std::string& homeurl, std::string& platform, const int disablefullscreen
        , const std::string& srvagency, const std::uint32_t agengcy_id, const std::set<std::string>& srvlang
        , const std::string& currency, const std::int64_t& currency_unit_multi, const std::string& currency_label, const std::set<std::string>& white_ips
        , const std::string& encode_key, const std::string& url, const int state, const std::vector<std::string>& agent_url, const std::set<std::uint32_t>& gamelist, const std::string& extern_json);
	static void gameinfoProc(const std::uint32_t request_id, const std::uint64_t request_time, const std::string& auth_url, const std::string& lauch_url, const std::uint32_t gameid
		, std::string& agency, const std::uint32_t agengcy_id, std::string& token, std::string& homeurl, std::string& platform, std::uint32_t display_mode
		, const std::int32_t fullscreen, const std::string& currency, const std::int64_t& currency_unit_multi, const std::string& currency_label, std::string& agent_url, const std::string& lang, const std::string& extern_json);
    static bool ValidUserName(const std::string& username);
};















